package com.wangjiyuan.giftshuo.ui.fragment.listtop.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.wangjiyuan.giftshuo.R;
import com.wangjiyuan.giftshuo.bean.listtopbean.maybelikebean.MayBeLikeBean;
import com.wangjiyuan.giftshuo.ui.fragment.listtop.helper.RecyclerViewAdapterHelper;

import java.util.List;

/**
 * Created by ZangSyeriong on 2016/11/23.
 */

public class DetailsRecommendRecyclerViewAdapter extends RecyclerViewAdapterHelper<MayBeLikeBean.DataBean.RecommendPostsBean>{

    public DetailsRecommendRecyclerViewAdapter(Context context, List<MayBeLikeBean.DataBean.RecommendPostsBean> list) {
        super(context, list);
    }

    @Override
    public RecyclerView.ViewHolder onCreateMyViewHolder(ViewGroup parent, int viewType) {
        View view = mInflater.inflate(R.layout.item_rv_recommend, parent, false);
        return new DetailsRecommendRecyclerViewAdapter.MyViewHolder(view);
    }

    @Override
    public void onBindMyViewHolder(RecyclerView.ViewHolder holder, final int position) {
        MayBeLikeBean.DataBean.RecommendPostsBean recommendPostsBean = mList.get(position);
        if (holder != null){
            Glide.with(mContext)
                    .load(recommendPostsBean.getCoverWebpUrl())
                    .fitCenter()
                    .placeholder(R.mipmap.post_place_holder_image)
                    .into(((MyViewHolder)holder).img_item_recommend);
            ((MyViewHolder) holder).tv_item_recommend.setText(
                    recommendPostsBean.getTitle());

            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(mContext, "I am a crazy man!", Toast.LENGTH_SHORT).show();
                }
            });
        }
    }
    static class MyViewHolder extends RecyclerView.ViewHolder{

        private ImageView img_item_recommend;
        private TextView tv_item_recommend;

        public MyViewHolder(View itemView) {
            super(itemView);

            img_item_recommend = (ImageView) itemView.findViewById(R.id.img_item_recommend);
            tv_item_recommend = (TextView) itemView.findViewById(R.id.tv_item_recommend);
        }
    }
}
